package com.titan.demo.camel.sample.eip.enricher;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;

import com.titan.demo.camel.utils.RunCamel;

public class TestPollEnrich {
	public static void main(String[] args) {
        try {
        	RouteBuilder route = createRouteBuilder();
        	createRunCamel().run(route);
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	
	private static RunCamel createRunCamel() {
		return new RunCamel() {
			protected void execute(CamelContext context,
					ProducerTemplate producer, ConsumerTemplate consumer)
					throws Exception {
				producer.sendBody("direct:resource", "源数据");
			}
		};
	}
	
	private static RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("direct:resource")
                .transform().simple("被合并数据")
                .to("stream:out")
                // 注意：对于pollEnrich的Exchange的数据没有用，也不要试图想从当前的Exchange（这里等同于Message）获取任何信息，比如Header。
                .pollEnrich("file:C:/zzz/mvn/camel/inbox?fileName=inbox.txt&charset=UTF-8")
                .to("stream:out")
                ;
            }
        };
    }
}
